home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / handle20.zip / FILES3X.ASM < prev    next >
Assembly Source File  |  1987-07-17  |  18KB  |  397 lines

  1. ;****************************************************************************
  2. ; file: files3x.asm    by: Steven M. Gibson, Irvine, CA        created: 06/06/87
  3. ;****************************************************************************
  4. ;
  5. ;          * * * PUBLIC DOMAIN COPYRIGHT RELEASE NOTICE * * *
  6. ;
  7. ; THIS PROGRAM, IN BOTH SOURCE CODE AND OBJECT FORM, HAS BEEN EXPLICITLY
  8. ; PLACED INTO THE PUBLIC DOMAIN BY ITS SOLE AUTHOR AND OWNER, STEVEN GIBSON,
  9. ; OF IRVINE, CA.  IT MAY THEREFORE BE FREELY REPRODUCED, EXCHANGED, UPLOADED
  10. ; AND DOWNLOADED.   HOWEVER THE AUTHOR REQUESTS THAT THIS NOTICE OF RELEASE
  11. ; AND ORIGIN OF AUTHORSHIP BE LEFT INTACT AND THAT THIS PROGRAM OR ITS DIRECT
  12. ; DERRIVATIVES, IF ANY, *NOT* BE SOLD FOR PROFIT.     ALSO, PLEASE KEEP THE
  13. ; ENTIRE SET OF FILES TOGETHER AS ONE PACKAGE.               ----> Thanks
  14. ;
  15. ;****************************************************************************
  16. ;
  17. ;  About The Program: FILES.COM              (source code file: files3x.asm)
  18. ;
  19. ;  "FILES.COM" is a small resident (TSR) program which overcomes a major
  20. ;  glitch in the way IBM has implemented DOS 3.30.  Specifically, it handles
  21. ;  the requirements of explicitly ASKING DOS for additional handles and
  22. ;  keeping a block of RAM available for DOS when this request is made.
  23. ;  Any program can now have up to 256 files open when under 3.0-3.2 (counting
  24. ;  the standard pre-opened default files) if the command "FILES" is issued
  25. ;  first.  This program also has the interesting ability to spontaneously
  26. ;  remove itself ("Un-TSR") from memory after doing its job.
  27. ;
  28. ;  If you wish to suppress the message FILES delivers when it is run, simply
  29. ;  put anything after the command, (like: "files shhh") and it won't say a
  30. ;  word as it goes resident. Otherwise it makes a short (non-commercial)
  31. ;  statement of its intent as it terminates.
  32. ;
  33. ;  NOTE:  This program *ONLY* makes sense when under versions 3.0 thru 3.2
  34. ;         of DOS, and will refuse to run under any earlier DOS versions.
  35. ;      Use the other DOS 3.3 version of FILES.COM  (source: files3x.asm)
  36. ;****************************************************************************
  37. ;
  38. ;             About These SOURCE CODE FILES:
  39. ;
  40. ;  This source code file, and the companion OPENER.ASM source code file, were
  41. ;  written to be instructional, clear, and a bit tutorial in nature. As such
  42. ;  they have been commented more heavily than normal self-communication
  43. ;  would normally dictate.  I hope you will find them interesting, useful,
  44. ;  and not overly verbose.  They are also examples of a general coding style
  45. ;  I've found to endure quite well.  Adopt it if you like it.
  46. ;
  47. ;  NOTE: These files were created using the incredible file editor: BRIEF
  48. ;
  49. ;****************************************************************************
  50. ;
  51. ;    To make a COM file from this ASM source code:
  52. ;
  53. ;    masm files3x, files3x;        <--- assemble the .asm to .obj
  54. ;    link files3x;            <--- link the .obj to .exe
  55. ;    exe2bin files3x files3x.com    <--- convert .exe to .com
  56. ;    del files3x.obj            <--- delete the intermediate debris
  57. ;    del files3x.exe
  58. ;
  59. ;****************************************************************************
  60.  
  61. ;----------------------------------------------------------------------------
  62. ;                 E Q U A T E S
  63. ;----------------------------------------------------------------------------
  64. CR            equ    0Dh
  65. LF            equ    0Ah
  66. COM_TERMINATE        equ    20h        ; .COM program termination
  67.  
  68. DOS_FUNC        equ    21h        ; Interrupt to call DOS
  69.  DOS_PRINTSTRING    equ    09h        ; Dos Sub-Function Defs
  70.  DOS_SET_VECTOR        equ    25h
  71.  DOS_VERSION_NUMBER    equ    30h        ;    "    "
  72.  DOS_STAY_RESIDENT    equ    31h
  73.  DOS_GET_VECTOR        equ    35h
  74.  DOS_CREATE        equ    3Ch        ;    "    "
  75.  DOS_OPEN        equ    3DH
  76.  DOS_ALLOC        equ    48H
  77.  DOS_DEALLOC        equ    49H
  78.  DOS_SETBLOCK        equ    4AH
  79.  DOS_EXEC        equ    4BH
  80.  DOS_GET_PSP        equ    62h
  81.  SET_HANDLE_COUNT    equ    67h
  82.  
  83. NEW_MAX_HANDLES        equ    256        ; assuming 256 handle params
  84. MINIMUM_VERSION        equ    3 * 256 + 00    ; later than ver: "3"."00"
  85. MAXIMUM_VERSION        equ    3 * 256 + 30    ; earlier than ver: "3"."30"
  86. HANDLE_CLOSED_FLAG    equ    0FFh
  87.  
  88. ;----------------------------------------------------------------------------
  89. ;                  M A C R O S
  90. ;----------------------------------------------------------------------------
  91. zero    MACRO p1            ; this little macro is just too
  92.         xor    p1,p1        ; handy to be without.  Since it
  93.     ENDM                ; "cleanly" zeros any register.
  94.  
  95. ;----------------------------------------------------------------------------
  96. ;               C O D E    S E G M E N T
  97. ;----------------------------------------------------------------------------
  98. CODESEG    SEGMENT BYTE PUBLIC
  99.     ASSUME    CS:CODESEG, DS:CODESEG
  100.     ORG    02Ch            ; pointer to this program's environ
  101. Environment    LABEL WORD
  102.  
  103.     ORG    032h            ; maximum process file handles
  104. MaxHandleCount    LABEL WORD
  105.  
  106.     ORG    034h            ; offset of the handle pointer table
  107. HandleTableOff    LABEL WORD
  108.  
  109.     ORG    036h            ; maximum process file handles
  110. HandleTableSeg    LABEL WORD    
  111.  
  112.     ORG    080h
  113. ParameterCount    LABEL BYTE        ; count of the command-line params
  114.  
  115.     ORG    100h            ; .com programs execute from 0100h
  116. ComStart:    jmp    TransientCode    ; jump past the resident portion
  117.  
  118. ;****************************************************************************
  119. ;               RESIDENT CODE PORTION BEGINS HERE
  120. ;****************************************************************************
  121.  
  122.  
  123. OldDosInt    dd    ?        ; original int 21 vector pointer
  124. TriggerEnable    db    0        ; non-zero after enabling EXEC call
  125. HoleSegment    dw    ?        ; segment location of the "hole"
  126.  
  127. ;----------------------------------------------------------------------------
  128. ; NOTE TO THE READER:  The following "resident portion" of the TSR will make
  129. ; *MUCH* more sense if you have FIRST read the "transient portion" below. I
  130. ; suggest that you jump ahead and read that first, then come back to here....
  131. ;----------------------------------------------------------------------------
  132.  
  133. Int21Intercept:
  134. ;----------------------------------------------------------------------------
  135. ;   The transient portion of this program pointed DOS' calling Interrupt 21
  136. ;   here before terminating itself.  Therefore we receive control every time
  137. ;   anyone does an Int21h call to DOS.  (Until we've fulfilled our mission)
  138. ;----------------------------------------------------------------------------
  139.         cmp    ah, DOS_EXEC        ; is DOS starting a program?
  140.         jne    NotEnablingCall        ; nope, so skip the enabling
  141.         mov    cs:TriggerEnable, -1    ; yes!, so we simply enable
  142.         jmp    Int21Continue        ; and resume Int21 monitoring
  143.  
  144. NotEnablingCall:cmp    ah, DOS_OPEN        ; was the call an open handle?
  145.         je    SeeIfReady        ; yep, are we ready to go?
  146.         cmp    ah, DOS_CREATE        ; was it a create handle?
  147.         je    SeeIfReady        ; yep ....
  148. AbortIntercept:    jmp    Int21Continue        ; (too far for a cond. jmp)
  149.  
  150. SeeIfReady:    cmp    cs:TriggerEnable, 0    ; have we been enabled by EXEC
  151.         je    AbortIntercept        ; nope, so ignore the OPEN
  152.  
  153.         cmp    cs:HoleSegment, 0    ; did we already do our thing?
  154.         je    AbortIntercept        ; yep, so don't do it again!
  155.  
  156.         push    ax            ; save the caller's calling
  157.         push    bx            ; parameters on his own stack
  158.         push    cx
  159.         push    si
  160.         push    di
  161.         push    ds
  162.         push    es
  163.  
  164. ;----------------------------------------------------------------------------
  165. ;  Free up the memory block, located at "HoleSegment", which was previously
  166. ;  allocated by (and therefore owned by) our transient portion 
  167. ;----------------------------------------------------------------------------
  168.         mov    es, cs:HoleSegment    ; get the segment number
  169.         mov    cs:HoleSegment, 0    ; zero it so we don't again
  170.         mov    ah, DOS_DEALLOC
  171.         int    DOS_FUNC        ; and release that ram block 
  172.  
  173. ;----------------------------------------------------------------------------
  174. ;  And now we reallocate it (or maybe some other free chunk lying around)
  175. ;  to the CURRENTLY running process's identity.  This way the current
  176. ;  process "owns" the block so it too will be released when he terminates.
  177. ;----------------------------------------------------------------------------
  178.         mov    bx, (NEW_MAX_HANDLES+15)/16    ; use paragraphs
  179.         mov    ah, DOS_ALLOC
  180.         int    DOS_FUNC
  181.         mov    es, ax        ; and hold onto the block's segment
  182.  
  183.  
  184. ;-----------------------------------------------------